import 'package:common_utils/common_utils.dart';
import 'package:part_time_job_pro/common/exception/exp_handler.dart';
import 'package:part_time_job_pro/common/utils/def_type.dart';
import 'package:part_time_job_pro/common/utils/request_util.dart';
import 'package:part_time_job_pro/common/values/respones_code.dart';
import 'package:part_time_job_pro/common/values/server_config.dart';

///错误上报
class ReportApi {
  late RequestUtil apiUtil;
  //创建实例
  ReportApi() {
    apiUtil = RequestUtil.getInstance();
  }
  /*
   * 上传错误日志
   * @param businessType 业务类型
   * @param errorMsg 日志信息
   * @param title 模块信息
   * @param status 上报类别（0程序 1人工）
   * @param mobile 手机号
   */
  void reportErrorStack(RequestCallBack requestCallBack, String businessType,
      String errorMsg, String title,
      {String? status = "0", String? method, String? param}) async {
    try {
      Map<String, dynamic> params = {
        "businessType": businessType,
        "errorMsg": errorMsg,
        "title": title,
        "status": status,
        "method": method,
        "param": param
      };
      LogUtil.e("请求参数params===$params");
      var result = await apiUtil.post(HttpConfig.reportErrorStack,
          decode: true, data: params);
      int resultCode = result[ResponesCode.codeTag];
      var resultData = result[ResponesCode.msgTag];
      if (resultCode == ResponesCode.successCode) {
        LogUtil.e("返回上报日志结果:$resultData");
        requestCallBack(result);
      } else {
        requestCallBack(result);
      }
    } catch (e) {
      requestCallBack(ExceptionHandler.handleDataException(e));
    }
  }
}
